package com.gxa.hystrix.service;

import com.gxa.hystrix.interfaces.YaoFangFeignByCheck;
import com.gxa.hystrix.pojo.YaoFang;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author thinknovo
 * @version 1.0
 * @description CheckService.java
 * @date 2021/3/11 9:25
 */
@Service
public class YaoFangService {
    @Resource
    private YaoFangFeignByCheck yaoFangFeignByCheck;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解checkError定义的方法
    // 熔断器会检查所有的client是否存在，如果都不存在，则会触发HystrixCommand
//    @HystrixCommand(fallbackMethod = "checkError")
//    public Map check(String username) {
//        return serviceFeignByCheck.selectClient(username);
//    }
//    public Map checkError(String username) {
//        Map map = new HashMap();
//        map.put("code", 500);
//        map.put("msg","服务异常，请稍后重试！");
//        return map;
//    }

    @HystrixCommand(fallbackMethod = "chaXunAllError")
    public Map yaoFangChaXunAll() {
        return yaoFangFeignByCheck.yaoFangChaXunAll();
    }
    public Map chaXunAllError() {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "gengXinByIdError")
    public Map yaoFangGengXinById(YaoFang yaoFang) {
        return yaoFangFeignByCheck.yaoFangGengXinById(yaoFang);
    }
    public Map gengXinByIdError(YaoFang yaoFang) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }



    @HystrixCommand(fallbackMethod = "yaoFangShanChuByIdError")
    public Map yaoFangShanChuById(String id) {
        return yaoFangFeignByCheck.yaoFangShanChuById(id);
    }
    public Map yaoFangShanChuByIdError(String id) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
//
@HystrixCommand(fallbackMethod = "chuShouByIdError")
public Map yaoFangChuShouById(YaoFang yaoFang) {
    return yaoFangFeignByCheck.yaoFangChuShouById(yaoFang);
}
    public Map chuShouByIdError(YaoFang yaoFang) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
//
@HystrixCommand(fallbackMethod = "yaoFangDiaoRuByIdError")
public Map yaoFangDiaoRuById(int id, int diaoRuYaoFangShuLiang) {
    return yaoFangFeignByCheck.yaoFangDiaoRuById(id,diaoRuYaoFangShuLiang);
}
    public Map yaoFangDiaoRuByIdError(int id,int diaoRuYaoFangShuLiang) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
//
@HystrixCommand(fallbackMethod = "xinZengError")
public Map yaoFangXinZeng(YaoFang yaoFang) {
    return yaoFangFeignByCheck.yaoFangXingZeng(yaoFang);
    }
    public Map xinZengError(YaoFang yaoFang) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

    @HystrixCommand(fallbackMethod = "xiaZaiMuBanError")
    public Map yaoFangXiaZaiMuBan(HttpServletResponse response, @RequestParam("ids") List<String> ids) {
        return yaoFangFeignByCheck.yaoFangXiaZaiMuBan(response,ids);
    }
    public Map xiaZaiMuBanError(HttpServletResponse response, @RequestParam("ids") List<String> ids) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
//    @HystrixCommand(fallbackMethod = "guaHaoJiLuTuiHaoByIdError")
//    public Map guaHaoJiLuTuiHaoById(String id) {
//        return serviceFeignByCheck.guaHaoJiLuTuiHaoById(id);
//    }
//    public Map guaHaoJiLuTuiHaoByIdError(String id) {
//        Map map = new HashMap();
//        map.put("code", 500);
//        map.put("msg","服务异常，请稍后重试！");
//        return map;
//    }
//
//    @HystrixCommand(fallbackMethod = "guaHaoJiLuXinZengError")
//    public Map guaHaoJiLuXinZeng(GuaHaoJiLu guaHaoJiLu) {
//        return serviceFeignByCheck.guaHaoJiLuXinZeng(guaHaoJiLu);
//    }
//    public Map guaHaoJiLuXinZengError(GuaHaoJiLu guaHaoJiLu) {
//        Map map = new HashMap();
//        map.put("code", 500);
//        map.put("msg","服务异常，请稍后重试！");
//        return map;
//    }




}
